//
//  CategoryViewController.m
//  美团
//
//  Created by Ansen on 15-3-7.
//  Copyright (c) 2015年 Ansen. All rights reserved.
//

#import "CategoryViewController.h"
#import "HomeDropdown.h"
#import "UIView+Extension.h"
#import "Categorys.h"
#import "MJExtension.h"
#import "MetaTool.h"
#import "Const.h"

@interface CategoryViewController ()<HomeDropdownDataSource,HomeDropdownDelegate>

@end

@implementation CategoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    HomeDropdown *dropdown = [HomeDropdown dropdown];
    dropdown.dataSource = self;
    dropdown.delegate = self;
    [self.view addSubview:dropdown];
    
    self.preferredContentSize = dropdown.size;
    
}

-(NSInteger)numberOfRowsInMainTable:(HomeDropdown *)homeDropdown
{
    return [MetaTool categories].count;
}

-(NSString *)homeDropdown:(HomeDropdown *)homeDropdown titleForRowInMainTable:(int)row
{
    Categorys *category = [MetaTool categories][row];
    return category.name;
}

-(NSArray *)homeDropdown:(HomeDropdown *)homeDropdown subDataForRowInMainTable:(int)row
{
    Categorys *category = [MetaTool categories][row];
    return category.subcategories;
}

-(NSString *)homeDropdown:(HomeDropdown *)homeDropdown iconForRowInMainTable:(int)row
{
    Categorys *category = [MetaTool categories][row];
    return category.small_highlighted_icon;
}

-(NSString *)homeDropdown:(HomeDropdown *)homeDropdown selectedIconForRowInMainTable:(int)row
{
    Categorys *category = [MetaTool categories][row];
    return category.small_highlighted_icon;
}

-(void)homeDropdown:(HomeDropdown *)homeDropdown didSelectRowInMainTable:(int)row
{
    Categorys *category = [MetaTool categories][row];
    if (category.subcategories.count == 0) {
        [NotificationCenter postNotificationName:CategoryDidChangeNotification object:nil userInfo:@{SelectCategory:category}];
    }
}

-(void)homeDropdown:(HomeDropdown *)homeDropdown didSelectRowInSubTable:(int)subRow inMainTable:(int)mainRow
{
    Categorys *category = [MetaTool categories][mainRow];
    [NotificationCenter postNotificationName:CategoryDidChangeNotification object:nil userInfo:@{SelectCategory:category,SelectSubcategoryName:category.subcategories[subRow]}];
}
@end
